package com.itheima.spring.factory;

import com.itheima.spring.pojo.Student;
import org.springframework.beans.factory.FactoryBean;

/**
 * @author ：sean
 * @date ：Created in 2020/7/10
 * @description ：
 * @version: 1.0
 */
public class StudentFactoryBean implements FactoryBean {
	public void setStudentInfo(String studentInfo) {
		this.studentInfo = studentInfo;
	}

	private String studentInfo;
	@Override
	public Object getObject() throws Exception {
		if (this.studentInfo == null) {
			throw new IllegalArgumentException("无效信息");
		}

		String[] splitStudentInfo = studentInfo.split(",");
		if (null == splitStudentInfo || splitStudentInfo.length != 3) {
			throw new IllegalArgumentException("数据格式错误，无法初始化");
		}
		Student student = new Student();
		student.setName(splitStudentInfo[0]);
		student.setAge(Integer.valueOf(splitStudentInfo[1]));
		student.setClassName(splitStudentInfo[2]);
		return student;
	}

	@Override
	public Class<?> getObjectType() {
		return Student.class;
	}
	public boolean isSingleton() {
		return true;
	}
}
